package cn.e4j.modular.crm.service.impl;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.modular.crm.entity.EsabT;
import cn.e4j.modular.crm.mapper.EsabTMapper;
import cn.e4j.modular.crm.service.EsabTService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuw
 * @since 2019-11-07
 */
@Service
public class EsabTServiceImpl extends ServiceImpl<EsabTMapper, EsabT> implements EsabTService {
    @Override
    public List<Map<String, Object>> getEsablist(Page<Object> page, Dto inDto) {
        return this.baseMapper.getEsablist(page, inDto);
    }

    @Override
    public boolean existedTheParams(EsabT esabT) {
        QueryWrapper<EsabT> esabTQueryWrapper = new QueryWrapper<>();
        esabTQueryWrapper.eq("ESAB003", esabT.getESAB003());

        QueryWrapper<EsabT> esabTQueryWrapper2 = new QueryWrapper<>();
        esabTQueryWrapper2.eq("ESAB001", esabT.getESAB001());
        return this.baseMapper.selectCount(esabTQueryWrapper) > 0 ||
                this.baseMapper.selectCount(esabTQueryWrapper2) > 0;
    }

    @Override
    public void add(EsabT esabT) {
        esabT.insert();
    }

    @Override
    public void edit(EsabT esabT) {
        UpdateWrapper<EsabT> esabTQueryWrapper = new UpdateWrapper<>();
        esabTQueryWrapper.eq("ESAB001", esabT.getESAB001());
        esabTQueryWrapper.eq("ESAB003", esabT.getESAB003());
        esabT.update(esabTQueryWrapper);
    }

    @Override
    public void delete(EsabT esabT) {
        UpdateWrapper<EsabT> esabTQueryWrapper = new UpdateWrapper<>();
        esabTQueryWrapper.eq("ESAB003", esabT.getESAB003());
        esabT.delete(esabTQueryWrapper);
    }

    @Override
    public void deleteBatch(List<EsabT> esabTList) {
        for (EsabT esabT : esabTList) {
            delete(esabT);
        }
    }

    @Override
    public Dto getEsabByEsab003(String esab003) {
        return this.baseMapper.getEsabByEsab003(esab003);
    }
    @Override
    public Dto getEsabByEsab001(String esab001) {
        return this.baseMapper.getEsabByEsab001(esab001);
    }


    @Override
    public List<Dto> getGwalByEsab001(String esab001) {
        return this.baseMapper.getGwalByEsab001(esab001);
    }

    @Override
    public List<Dto> getGwadList(Dto inDto) {
        return this.baseMapper.getGwadList(inDto);
    }

}
